import { message } from 'antd';
import { getEntrymanaList, editDate, entryDelete } from '@/services/entryManagement/entryManagement';

export default {
    namespace: 'entryManagement',
    state: {
        entrymanaList: [],
        pagination: {
            current: 1,
            pageSize: 10,
            total: 0
        }
    },
    effects: {
        // 假期管理列表
        *fetchEntrymanaList({ payload }, { call, put }) {
            console.log('时间');
            const result = yield call(getEntrymanaList, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        entrymanaList: result.data.rows,
                        pagination: {
                            pageSize: result.data.pageSize,
                            current: result.data.pageNo,
                            total: result.data.total
                        }
                    }
                });
            }
        },
        // 入职日期更改
        *editDate({ payload, success }, { call }) {
            // alert(22);
            const result = yield call(editDate, payload);
            if (result.code === 10000) {
                message.success(result.msg);
                // eslint-disable-next-line no-unused-expressions
                success && success();
            } else {
                message.error(result.msg);
            }
        },
        // 取消入职
        *cancleEntry({ payload, success }, { call }) {
            console.log('payload', payload);
            const result = yield call(entryDelete, payload);
            if (result.code === 10000) {
                message.success(result.msg);
                // eslint-disable-next-line no-unused-expressions
                success && success();
            } else {
                message.error(result.msg);
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
